package site.wanjiahao.queue;

import site.wanjiahao.heap.BinaryHeap;
import site.wanjiahao.heap.Heap;

import java.util.Comparator;

// 对于优先级队列，可以使用二叉堆来实现
public class PriorityQueue<E> implements Queue<E>{

    // 需要传入一个比较器，或者实现comparable接口
    private final Heap<E> heap;

    public PriorityQueue(Comparator<E> comparator) {
        heap = new BinaryHeap<>(comparator);
    }

    public PriorityQueue() {
        this(null);
    }

    @Override
    public int size() {
        return heap.size();
    }

    @Override
    public boolean isEmpty() {
        return heap.isEmpty();
    }

    @Override
    public void clear() {
        heap.clear();
    }

    @Override
    public void enQueue(E e) {
        heap.add(e);
    }

    @Override
    public E deQueue() {
        return heap.remove();
    }

    @Override
    public E front() {
        return heap.get();
    }
}
